<?php

class Catalogue_Model_Category_Observer_AttributePriority extends Workset_Model_Observer_Abstract {

	private $_value = null;

	function beforeUnlinkObject(Workset_Model_Subject_Interface $category, $attr = null)
	{
		$this->_value = null;

		if ($attr instanceof Catalogue_Model_Attribute) {
			$this->_value = $category->getAttributePriority($attr);
		}
	}

	function afterUnlinkObject(Workset_Model_Subject_Interface $category, $attr = null)
	{
		if (null !== $this->_value && $attr instanceof Catalogue_Model_Attribute) {            
			$where = array(
				'priority > ?' => $this->_value
			);

			$category->updateAttributePriority($where, -1);
		}

		$this->_value = null;
	}

}